/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.umss.arqui10.modelo;

import java.io.Serializable;
import java.util.LinkedList;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;
import javax.persistence.Column;
import javax.persistence.Table;

/**
 * Titular
 *
 * @author rho1and0
 */
@Entity
@Table(name="Holder")
public class Holder implements Serializable {

    @Column(name="name")
    private String name;

    @Column(name="address")
    private String address;

    @Column(name="phone")
    private String phone;

    @Column(name="email")
    private String email;

    private boolean debt;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private String nit;
    private LinkedList<Account> account;

    public Holder() {
    }
    public Holder(String name) {
        this.name = name;
        this.debt = false;
    }

    public Holder(Long id) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public boolean getDebt(){
        return debt;
    }

    public void setDebt(boolean debt) {
        this.debt = debt;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    public Long getId() {
        return id;
    }

     public void setId(Long id) {
        this.id = id;
    }
    public String getNit() {
        return nit;
    }

    public void setNit(String nit) {
        this.nit=nit;
    }

    public void persist(Object object) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("SistemaGeneralPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }

    public Account getAccount() {
        return account.getLast();
    }
}
